package com.louzhu.gulimall.cart.vo;

import java.math.BigDecimal;
import java.util.List;

/**
 * 购物车vo
 */
public class CartVo {
    List<CartItemVo> items;
    private Integer countNum; // 所有商品件数
    private Integer countType; // 所有商品种数，
    private BigDecimal totalAmount; // 商品总价
    private BigDecimal reduce=new BigDecimal("0"); // 所有商品优惠价

    public List<CartItemVo> getItems() {
        return items;
    }

    public void setItems(List<CartItemVo> items) {
        this.items = items;
    }

    /*
    计算总件数
     */
    public Integer getCountNum() {
        int count = 0;
        if(null != items && items.size()>0){
            for (CartItemVo item: items) {
                count += item.getCount();
            }
        }
        return count;
    }

    /*
    计算所有商品的种类数
     */
    public Integer getCountType() {
        int count = 0;
        if(null != items && items.size()>0){
            for (CartItemVo item: items) {
                count += 1;
            }
        }
        return count;
    }

    /*
    计算所有商品的总价
     */
    public BigDecimal getTotalAmount() {
        // 计算购物项总价
        BigDecimal amount = new BigDecimal("0");
        if(null != items && items.size()>0){
            for (CartItemVo item:items) {
                amount = amount.add(item.getTotalPrice());
            }
        }
        // 减去优惠总价
        amount = amount .subtract(getReduce());
        return amount ;
    }



    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
